home *** CD-ROM | disk | FTP | other *** search
- Path: news.clark.net!not-for-mail
- From: gusty@clark.net (Harlan Messinger)
- Newsgroups: comp.lang.c++
- Subject: Re: Fastest way to index thru an array????
- Date: 11 Jan 1996 19:27:00 GMT
- Organization: Clark Internet Services, Inc., Ellicott City, MD USA
- Message-ID: <4d3oa4$uj@clarknet.clark.net>
- References: <4d1g3k$o09@solaris.cc.vt.edu> <4d34p7$kj9@tahko.lpr.carel.fi>
- NNTP-Posting-Host: explorer.clark.net
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
- X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
-
- Ari Lukumies (aril@cmt.lpr.mail.carel.fi) wrote:
- : Try this:
- :
- : double *p = A;
- :
- : for (i = 0; i < 50*60*70; i++)
- : *p++ = <some expression>;
- :
- : BTW, array indexes in C/C++ begin at 0, _not_ at 1.
- :
-
- !!!!! NO !!!!!
-
- A is a constant pointer to an array of 50 pointers, each of which points
- to an array of 60 pointers, each of which points to an array of 70
- doubles. The arrays of doubles are not necessarily contiguous, and A does
- not point to any of them.
-
- A is (double const ***). p is (double *). If p, which points to doubles,
- is assigned the value of A, which points to pointers, we have gibberish.
-
- The original writer's solution is almost the most efficient possible, the
- most efficient being the one with pointer iteration that has already been
- left here as a response by someone else. That solution substitutes
- incrementing for addition in each pass through the loop.
-